package RecoverCal;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.BitSet;
import java.util.Scanner;

public class RecoverCal {

	/**
	 * @param args
	 * @throws FileNotFoundException
	 */
	public static void main(String[] args) throws FileNotFoundException {
		//String file = "src/RecoverCal/B-small-attempt3.in";
		String file = "src/RecoverCal/B-large.in";
		//String file = "src/RecoverCal/test.txt";
		Scanner sc = new Scanner(new File(file));

		int nSets;
		nSets = sc.nextInt();
		sc.nextLine();

		for (int i = 1; i <= nSets; i++) {
			String[] pars = sc.nextLine().split(" ");

			BitSet posQ1 = new BitSet(pars[0].length());
			BitSet posQ2 = new BitSet(pars[2].length());
			BitSet posQ3 = new BitSet(pars[4].length());

			for (int j = 0; j < pars[0].length(); j++) {
				if (pars[0].charAt(j) == '?') {
					posQ1.set(j, true);
				}
			}

			for (int j = 0; j < pars[2].length(); j++) {
				if (pars[2].charAt(j) == '?') {
					posQ2.set(j, true);
				}
			}

			for (int j = 0; j < pars[4].length(); j++) {
				if (pars[4].charAt(j) == '?') {
					posQ3.set(j, true);
				}
			}

			int a, b, c;
			a = init(posQ1, pars[0]);
			b = init(posQ2, pars[2]);
			c = init(posQ3, pars[4]);
			
			int x,y,z;
			x=a; y=b; z=c;
			
			boolean carryY = false,carryX = false;
			while(true) {
				
				
				
				if(pars[1].equalsIgnoreCase("+")) {
					if(x+y == z) {
						System.out.println("Case #" + i + ": " + x + " + " + y + " = " + z);
						break;
					}
				} else {
					if(x-y == z) {
						System.out.println("Case #" + i + ": " + x + " - " + y + " = " + z);
						break;
					}
				}
				
				if(posQ3.cardinality()>0) {
					z=next(posQ3, z);
					if (z==-1) {
						z=c;
						if (posQ2.cardinality() == 0) {
							carryX=true;
						} else {
							carryY=true;
						}
					}
				} else {
					if (posQ2.cardinality() == 0) {
						carryX=true;
					} else {
						carryY=true;
					}
				}
				
				if(carryY && posQ2.cardinality()>0) {
					carryY=false;
					y=next(posQ2, y);
					if (y==-1) {
						y=b;
						carryX=true;
					}
				} 
				
				if(carryX && posQ1.cardinality()>0) {
					carryX=false;
					x=next(posQ1, x);
					if (x==-1) {
						// never come here!
						y=b;
						carryX=true;
					}
				}
			}

			
		}
		sc.close();
	}

	static int init(BitSet a, String s) {
		int r = 0;
		int len = s.length();
		int scale = 1;
		for (int i = len - 1; i >= 0; i--) {
			int k = s.charAt(i) - 48;
			if (a.get(i)) {
				if (i == 0 && len > 1) {
					r = r + (1 * scale);
				}
			} else {
				r = r + (k * scale);
			}
			scale *= 10;
		}
		return r;
	}

	static int next(BitSet a, int n) {
		int r = n;

		String s = Integer.toString(r);
		int len = s.length();
		int scale = 1;
		for (int i = len - 1; i >= 0; i--) {
			if (a.get(i)) {
				int k = s.charAt(i) - 48;
				r = r - (k * scale);
				if (s.charAt(i) != '9') {
					r = r + ((k + 1) * scale);
					return r;
				}
			}
			scale *= 10;
		}
		return -1;
	}
}
